<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tweet_controller
 *
 * @author Tmblue
 */
class TweetController extends AppController{
    var $name = 'Tweet';

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Tweet->order = 'Tweet.id DESC';
    }

    function index(){

    }

    function update() {
        // query params
        if (!empty($this->params['named']['id']))
            $user_id = $this->params['named']['id'];
        else $user_id = null;

        if (!empty($this->params['named']['page']))
            $page = $this->params['named']['page'];
        else $page = 1;
        $condition = null;
        $limit = 5;
        // when you want to see what's people doing, leave $user_id = null
        // $user_id = null, that mean it will query all recently tweets by everyone.
        if (!empty($user_id)){
            $condition = array('Tweet.user_id' => $user_id);
        }

        $tweets = $this->Tweet->find('all',array(
                'conditions' => $condition,
                'limit' => $limit,
                'page' => $page,
                'callback' => true
            ));
        
        // check error
        if (count($tweets) == 0)
        {
            $this->Session->setFlash()
        }
        
        $this->set('tweets', $tweets);
    }

    function create(){
        
    }

}
?>
